using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;

namespace SolanumSolstice_Windows.Mapping
{
    public class Path
    {
        private List<PathNode> path;

        public List<PathNode> GetPath
        {
            get
            {
                return path;
            }
            set
            {
                path = value;
            }
        }

        public Path(Vector2 startPosition, Vector2 targetPosition, List<PathNode> closedList)
        {

            path = new List<PathNode>();

            int index = ListIndexOfPathNode(closedList, targetPosition);

            while(!ListContainsPathNode(path, startPosition))
            {
                path.Add(closedList[index]);
                index = closedList.IndexOf(closedList[index].Parent);
            }
            
        }

        public int ListIndexOfPathNode(List<PathNode> nodes, Vector2 position)
        {


            foreach (PathNode node in nodes)
            {
                if (node.Position == position)
                {
                    return nodes.IndexOf(node);
                }
            }

            return -1;
        }

        public bool ListContainsPathNode(List<PathNode> nodes, Vector2 position)
        {

            foreach (PathNode node in nodes)
            {
                if (node.Position == position)
                {
                    return true;
                }
            }

            return false;
        }



    }
}
